"""
队列的类型，先进先出，先进后出，优先级
"""
import random
import time
from concurrent.futures import ThreadPoolExecutor
from queue import LifoQueue, PriorityQueue, Queue

q1 = Queue()
q2 = LifoQueue()
q3 = PriorityQueue()


for i in "我爱你北极光":
    q1.put(i)
    q2.put(i)
    q3.put(i)


for i in range(6):
    print(f"第{i}次")
    print(f"q1: {q1.get(i)}")
    print(f"q2: {q2.get(i)}")
    print(f"q3: {q3.get(i)}")


# 生产者和消费者

q = Queue()


def task_a():
    """
    生产者向队列中放入数据
    :return:

    """
    for _ in range(5):
        x = random.randint(0, 99)
        print("向队列中放入数据", x)
        q.put(x)
        time.sleep(1)


def task_b():
    """
    消费者，从队列中取出数据
    :return:
    """
    for _ in range(5):
        y = q.get(timeout=2)
        print("从队列中获取的数据：", y)
        q.task_done()


start_time = time.time()
pool = ThreadPoolExecutor(max_workers=2)
pool.submit(task_a)
pool.submit(task_b)
pool.shutdown()


end_time = time.time()

print(f"total time:{end_time - start_time:.2f}")
